package com.jlnk.androidfmc;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageButton;

import java.util.ArrayList;
import java.util.List;

import com.jlnk.androidfmc.adapter.FavoritesAdapter;
import com.jlnk.androidfmc.entity.FavoriteItem;

public class FavoritesActivity extends AppCompatActivity {

    private RecyclerView recyclerViewFavorites;
    private FavoritesAdapter adapter;
    private List<FavoriteItem> favoritesList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_favorite);

        // 初始化数据和RecyclerView
        favoritesList = new ArrayList<>();
        initData();
        setupRecyclerView();

        // 设置返回按钮的点击事件
        findViewById(R.id.button_back).setOnClickListener(view -> finish());
    }

    private void setupRecyclerView() {
        recyclerViewFavorites = findViewById(R.id.recyclerViewFavorites);
        recyclerViewFavorites.setLayoutManager(new LinearLayoutManager(this));
        adapter = new FavoritesAdapter(favoritesList);
        recyclerViewFavorites.setAdapter(adapter);
    }



    private void initData() {
        // 这里添加一些示例数据
        favoritesList.add(new FavoriteItem(R.drawable.nm, "柠檬", 9.99));
        favoritesList.add(new FavoriteItem(R.drawable.apple, "苹果", 15.50));
        // 假设我们添加更多数据
        favoritesList.add(new FavoriteItem(R.drawable.jz, "橘子", 8.50));
        favoritesList.add(new FavoriteItem(R.drawable.cm, "草莓", 12.99));
        // 继续添加更多数据...

    }
}
